// router/index.js
import { createRouter, createWebHistory, type RouteRecordRaw } from 'vue-router'

const routes: RouteRecordRaw[] = [
  {
    path: '/',
    redirect: '/create',
    meta: { title: '首页' }
  },
  {
    path: '/preview',
    component: () => import('../pages/CreateHtml/index.vue'),
    name: 'preview',
    meta: { title: '预览页面' }
  },
  {
    path: '/create',
    component: () => import('../pages/CreateList/index.vue'),
    name: 'create',
    meta: { title: '创建表单' }
  },
  {
    path: '/group',
    component: () => import('../pages/GroupList/index.vue'),
    name: 'group',
    meta: { title: '填写表单详情' }
  },
  {
    path: '/demo',
    component: () => import('../pages/Demo/index.vue'),
    name: 'demo',
    meta: { title: 'demo' }
  }
]

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes,
  // 可选的滚动行为
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      return { top: 0 }
    }
  }
})

// 路由守卫示例
router.beforeEach((to, from, next) => {
  // 可以在这里添加权限验证等逻辑
  document.title = to.meta.title as string || '默认标题'
  next()
})

export default router